package com.jinke.uang.base;

import com.jinke.uang.interfaces.ICommonModule;
import com.jinke.uang.interfaces.ICommonView;

import java.lang.ref.SoftReference;

/**
 * 作者：Song Shuyu
 * 时间：2019/4/9 16:21
 * package is com.jinke.uang.mvp
 */
public class BasePersenter<V extends ICommonView,M extends ICommonModule>{

    private SoftReference<V> mVSoftReference;
    private SoftReference<M> mMSoftReference;

    public void attach(M module,V view){
        mVSoftReference = new SoftReference<>(view);
        mMSoftReference = new SoftReference<>(module);
    }

    public void deattch(){
        if(mVSoftReference!=null){
            mVSoftReference.clear();
            mVSoftReference=null;
        }
        if(mMSoftReference!=null){
            mMSoftReference.clear();
            mMSoftReference=null;
        }
    }

    public V getV(){
        return mVSoftReference!=null?mVSoftReference.get():null;
    }

    public M getM(){
        return mMSoftReference!=null?mMSoftReference.get():null;
    }
}
